package com.hjy;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class MyPredicateDemo {
    public static List<Student> filter(List<Student> studentList, Predicate<Student> predicate){
        List<Student> list = new ArrayList<Student>();
        studentList.forEach(s->{
            if (predicate.test(s) ){
                list.add(s);
            }
        });
        return list;
    }

    public static void main(String[] args) {
        List<Student> list = new ArrayList<Student>();
        list.add(new Student(1, "aE", "M"));
        list.add(new Student(2, "bE", "W"));
        list.add(new Student(3, "aF", "M"));
        //定义当前类中filter 中函数test 方法体
        List<Student> filter = filter(list, s -> s.getSex().equals("W"));
        System.out.println(filter.toString());
    }
}
